package net.kangyee.eventmanager.commands;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdFood extends EventManagerCommand {
	
	private EventManager plugin;
	
	public CmdFood(EventManager plugin){
		this.plugin = plugin;
	}

	public void onCommand(Player player, String[] args){
		int localNum = Integer.parseInt(args[1]);
    	if (localNum > 20 || localNum < 0){
    		MessageManager.sendNormalMessage(player, "&c饥饿值不可大于 20 或小于 0");
    		return;
    	}
    	if(args.length == 3){
    		if(!plugin.playerStateChecker(player, args[2])){
        		return;
        	}
    		Player targetPlayer = Bukkit.getPlayer(args[2]);
    		targetPlayer.setFoodLevel(localNum);
            MessageManager.sendNormalMessage(player, "玩家&6" + args[2] + "&f的饥饿值被你设置为:&6" + args[1]);
        	MessageManager.sendAdminMessage(targetPlayer, "你的饥饿值被管理员设置为:&6" + args[1]);   		
        	return;
    	}else{
    		for(Player localPlayer : plugin.regPlayers.keySet()){
    			localPlayer.setFoodLevel(localNum);
        		MessageManager.sendAdminMessage(localPlayer, "你的饥饿值被管理员设置为:&6" + args[1]);
            }
        	MessageManager.sendNormalMessage(player, "所有参加活动的玩家饥饿值被你设置为:&6" + args[1]);
    		return;
    	}
	}

	public String getCmdName(){
		return "food";
	}

	public String getArgs(){
		return "<饥饿值> [游戏名]";
	}
	
	public int getMaxArgs(){
		return 3;
	}

	public int getMinArgs(){
		return 2;
	}

	public String getPermission(){
		return "eventmanager.admin." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}
	
	public boolean getRegPCRequire() {
		return true;
	}
}
